package com.wenwei.activity;

import android.content.SharedPreferences;

import com.jaeger.library.StatusBarUtil;
import com.orhanobut.logger.Logger;
import com.wenwei.bean.ConfigBean;
import com.wenwei.bean.LoginBean;
import com.wenwei.net.ApiManager;
import com.wenwei.net.BaseSubscriber;
import com.wenwei.parking.BaseActivity;
import com.wenwei.parking.Constant;
import com.wenwei.parking.R;
import com.wenwei.utils.RogerSPUtils;

import java.util.concurrent.TimeUnit;

import rx.Observable;
import rx.functions.Action1;

/**
 * Created by Administrator on 2017/7/13.
 */
public class SplashActivity extends BaseActivity {
    @Override
    public int setLayoutResourceId() {
        return R.layout.activity_splash;
    }

    @Override
    protected void initView() {
        super.initView();
        StatusBarUtil.setTranslucent(this, 0);
    }

    @Override
    protected void initData() {
        super.initData();
        getConfig();
        Observable.just("").delay(2, TimeUnit.SECONDS).subscribe(new Action1<String>() {
            @Override
            public void call(String s) {
//                SharedPreferences sharedPreferences = getSharedPreferences("configuration", 0);
//                String name = sharedPreferences.getString("is_first","");
//                if(name==null || name.equals("")){
//                    goActivity(mContext,GuideActivity.class);
//                }else{
                    LoginBean ub = RogerSPUtils.getObject(mContext, Constant.SP_USER_LOGIN_RESULT,LoginBean.class);
                    if(ub == null){
                        goActivity(mContext,LoginActivity.class);
                    }else {
                        goActivity(mContext,HostActivity.class);
                    }
//                }
//                goActivity(mContext,LoginActivity.class);
                finish();

            }
        });


    }

    private BaseSubscriber<ConfigBean> configSb;
    private void getConfig(){
        configSb = new BaseSubscriber<ConfigBean>(mContext) {
            @Override
            public void onSuccess(ConfigBean configBean) {
                Logger.d("success config");
                RogerSPUtils.putObject(mContext, Constant.CONFIG,configBean);
            }
        };
        ApiManager.getInstance().getConfig(configSb);
    }
}
